<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="考试id" prop="examId">
        <el-input
          v-model="queryParams.examId"
          placeholder="请输入考试id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试名称" prop="examName">
        <el-input
          v-model="queryParams.examName"
          placeholder="请输入考试名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学员id" prop="studentId">
        <el-input
          v-model="queryParams.studentId"
          placeholder="请输入学员id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学员姓名" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目一分数" prop="subjectOne">
        <el-input
          v-model="queryParams.subjectOne"
          placeholder="请输入科目一分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目一速度" prop="subjectOneSpeed">
        <el-input
          v-model="queryParams.subjectOneSpeed"
          placeholder="请输入科目一速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目一评定" prop="subjectOneEvaluate">
        <el-input
          v-model="queryParams.subjectOneEvaluate"
          placeholder="请输入科目一评定"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目二分数" prop="subjectTwo">
        <el-input
          v-model="queryParams.subjectTwo"
          placeholder="请输入科目二分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目二速度" prop="subjectTwoSpeed">
        <el-input
          v-model="queryParams.subjectTwoSpeed"
          placeholder="请输入科目二速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目二评定" prop="subjectTwoEvaluate">
        <el-input
          v-model="queryParams.subjectTwoEvaluate"
          placeholder="请输入科目二评定"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目三分数" prop="subjectThree">
        <el-input
          v-model="queryParams.subjectThree"
          placeholder="请输入科目三分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目三速度" prop="subjectThreeSpeed">
        <el-input
          v-model="queryParams.subjectThreeSpeed"
          placeholder="请输入科目三速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目三评定" prop="subjectThreeEvaluate">
        <el-input
          v-model="queryParams.subjectThreeEvaluate"
          placeholder="请输入科目三评定"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目四分数" prop="subjectFour">
        <el-input
          v-model="queryParams.subjectFour"
          placeholder="请输入科目四分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目四速度" prop="subjectFourSpeed">
        <el-input
          v-model="queryParams.subjectFourSpeed"
          placeholder="请输入科目四速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目四评定" prop="subjectFourEvaluate">
        <el-input
          v-model="queryParams.subjectFourEvaluate"
          placeholder="请输入科目四评定"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目五分数" prop="subjectFive">
        <el-input
          v-model="queryParams.subjectFive"
          placeholder="请输入科目五分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目五速度" prop="subjectFiveSpeed">
        <el-input
          v-model="queryParams.subjectFiveSpeed"
          placeholder="请输入科目五速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目五评定" prop="subjectFiveEvaluate">
        <el-input
          v-model="queryParams.subjectFiveEvaluate"
          placeholder="请输入科目五评定"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目六分数" prop="subjectSix">
        <el-input
          v-model="queryParams.subjectSix"
          placeholder="请输入科目六分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目六速度" prop="subjectSixSpeed">
        <el-input
          v-model="queryParams.subjectSixSpeed"
          placeholder="请输入科目六速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目六评定" prop="subjectSixEvaluate">
        <el-input
          v-model="queryParams.subjectSixEvaluate"
          placeholder="请输入科目六评定"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目七分数" prop="subjectSeven">
        <el-input
          v-model="queryParams.subjectSeven"
          placeholder="请输入科目七分数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目七速度" prop="subjectSevenSpeed">
        <el-input
          v-model="queryParams.subjectSevenSpeed"
          placeholder="请输入科目七速度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科目七评定" prop="subjectSevenEvaluate">
        <el-input
          v-model="queryParams.subjectSevenEvaluate"
          placeholder="请输入科目七评定"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:achievement:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:achievement:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:achievement:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:achievement:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="achievementList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="考试id" align="center" prop="examId" />
      <el-table-column label="考试名称" align="center" prop="examName" />
      <el-table-column label="学员id" align="center" prop="studentId" />
      <el-table-column label="学员姓名" align="center" prop="studentName" />
      <el-table-column label="科目一分数" align="center" prop="subjectOne" />
      <el-table-column label="科目一速度" align="center" prop="subjectOneSpeed" />
      <el-table-column label="科目一评定" align="center" prop="subjectOneEvaluate" />
      <el-table-column label="科目二分数" align="center" prop="subjectTwo" />
      <el-table-column label="科目二速度" align="center" prop="subjectTwoSpeed" />
      <el-table-column label="科目二评定" align="center" prop="subjectTwoEvaluate" />
      <el-table-column label="科目三分数" align="center" prop="subjectThree" />
      <el-table-column label="科目三速度" align="center" prop="subjectThreeSpeed" />
      <el-table-column label="科目三评定" align="center" prop="subjectThreeEvaluate" />
      <el-table-column label="科目四分数" align="center" prop="subjectFour" />
      <el-table-column label="科目四速度" align="center" prop="subjectFourSpeed" />
      <el-table-column label="科目四评定" align="center" prop="subjectFourEvaluate" />
      <el-table-column label="科目五分数" align="center" prop="subjectFive" />
      <el-table-column label="科目五速度" align="center" prop="subjectFiveSpeed" />
      <el-table-column label="科目五评定" align="center" prop="subjectFiveEvaluate" />
      <el-table-column label="科目六分数" align="center" prop="subjectSix" />
      <el-table-column label="科目六速度" align="center" prop="subjectSixSpeed" />
      <el-table-column label="科目六评定" align="center" prop="subjectSixEvaluate" />
      <el-table-column label="科目七分数" align="center" prop="subjectSeven" />
      <el-table-column label="科目七速度" align="center" prop="subjectSevenSpeed" />
      <el-table-column label="科目七评定" align="center" prop="subjectSevenEvaluate" />
      <el-table-column label="描述" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:achievement:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:achievement:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改学员考试成绩管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="考试id" prop="examId">
          <el-input v-model="form.examId" placeholder="请输入考试id" />
        </el-form-item>
        <el-form-item label="考试名称" prop="examName">
          <el-input v-model="form.examName" placeholder="请输入考试名称" />
        </el-form-item>
        <el-form-item label="学员id" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入学员id" />
        </el-form-item>
        <el-form-item label="学员姓名" prop="studentName">
          <el-input v-model="form.studentName" placeholder="请输入学员姓名" />
        </el-form-item>
        <el-form-item label="科目一分数" prop="subjectOne">
          <el-input v-model="form.subjectOne" placeholder="请输入科目一分数" />
        </el-form-item>
        <el-form-item label="科目一速度" prop="subjectOneSpeed">
          <el-input v-model="form.subjectOneSpeed" placeholder="请输入科目一速度" />
        </el-form-item>
        <el-form-item label="科目一评定" prop="subjectOneEvaluate">
          <el-input v-model="form.subjectOneEvaluate" placeholder="请输入科目一评定" />
        </el-form-item>
        <el-form-item label="科目二分数" prop="subjectTwo">
          <el-input v-model="form.subjectTwo" placeholder="请输入科目二分数" />
        </el-form-item>
        <el-form-item label="科目二速度" prop="subjectTwoSpeed">
          <el-input v-model="form.subjectTwoSpeed" placeholder="请输入科目二速度" />
        </el-form-item>
        <el-form-item label="科目二评定" prop="subjectTwoEvaluate">
          <el-input v-model="form.subjectTwoEvaluate" placeholder="请输入科目二评定" />
        </el-form-item>
        <el-form-item label="科目三分数" prop="subjectThree">
          <el-input v-model="form.subjectThree" placeholder="请输入科目三分数" />
        </el-form-item>
        <el-form-item label="科目三速度" prop="subjectThreeSpeed">
          <el-input v-model="form.subjectThreeSpeed" placeholder="请输入科目三速度" />
        </el-form-item>
        <el-form-item label="科目三评定" prop="subjectThreeEvaluate">
          <el-input v-model="form.subjectThreeEvaluate" placeholder="请输入科目三评定" />
        </el-form-item>
        <el-form-item label="科目四分数" prop="subjectFour">
          <el-input v-model="form.subjectFour" placeholder="请输入科目四分数" />
        </el-form-item>
        <el-form-item label="科目四速度" prop="subjectFourSpeed">
          <el-input v-model="form.subjectFourSpeed" placeholder="请输入科目四速度" />
        </el-form-item>
        <el-form-item label="科目四评定" prop="subjectFourEvaluate">
          <el-input v-model="form.subjectFourEvaluate" placeholder="请输入科目四评定" />
        </el-form-item>
        <el-form-item label="科目五分数" prop="subjectFive">
          <el-input v-model="form.subjectFive" placeholder="请输入科目五分数" />
        </el-form-item>
        <el-form-item label="科目五速度" prop="subjectFiveSpeed">
          <el-input v-model="form.subjectFiveSpeed" placeholder="请输入科目五速度" />
        </el-form-item>
        <el-form-item label="科目五评定" prop="subjectFiveEvaluate">
          <el-input v-model="form.subjectFiveEvaluate" placeholder="请输入科目五评定" />
        </el-form-item>
        <el-form-item label="科目六分数" prop="subjectSix">
          <el-input v-model="form.subjectSix" placeholder="请输入科目六分数" />
        </el-form-item>
        <el-form-item label="科目六速度" prop="subjectSixSpeed">
          <el-input v-model="form.subjectSixSpeed" placeholder="请输入科目六速度" />
        </el-form-item>
        <el-form-item label="科目六评定" prop="subjectSixEvaluate">
          <el-input v-model="form.subjectSixEvaluate" placeholder="请输入科目六评定" />
        </el-form-item>
        <el-form-item label="科目七分数" prop="subjectSeven">
          <el-input v-model="form.subjectSeven" placeholder="请输入科目七分数" />
        </el-form-item>
        <el-form-item label="科目七速度" prop="subjectSevenSpeed">
          <el-input v-model="form.subjectSevenSpeed" placeholder="请输入科目七速度" />
        </el-form-item>
        <el-form-item label="科目七评定" prop="subjectSevenEvaluate">
          <el-input v-model="form.subjectSevenEvaluate" placeholder="请输入科目七评定" />
        </el-form-item>
        <el-form-item label="描述" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAchievement, getAchievement, delAchievement, addAchievement, updateAchievement } from "@/api/system/achievement";

export default {
  name: "Achievement",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学员考试成绩管理表格数据
      achievementList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        examId: null,
        examName: null,
        studentId: null,
        studentName: null,
        subjectOne: null,
        subjectOneSpeed: null,
        subjectOneEvaluate: null,
        subjectTwo: null,
        subjectTwoSpeed: null,
        subjectTwoEvaluate: null,
        subjectThree: null,
        subjectThreeSpeed: null,
        subjectThreeEvaluate: null,
        subjectFour: null,
        subjectFourSpeed: null,
        subjectFourEvaluate: null,
        subjectFive: null,
        subjectFiveSpeed: null,
        subjectFiveEvaluate: null,
        subjectSix: null,
        subjectSixSpeed: null,
        subjectSixEvaluate: null,
        subjectSeven: null,
        subjectSevenSpeed: null,
        subjectSevenEvaluate: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        examId: [
          { required: true, message: "考试id不能为空", trigger: "blur" }
        ],
        studentId: [
          { required: true, message: "学员id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询学员考试成绩管理列表 */
    getList() {
      this.loading = true;
      listAchievement(this.queryParams).then(response => {
        this.achievementList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        examId: null,
        examName: null,
        studentId: null,
        studentName: null,
        subjectOne: null,
        subjectOneSpeed: null,
        subjectOneEvaluate: null,
        subjectTwo: null,
        subjectTwoSpeed: null,
        subjectTwoEvaluate: null,
        subjectThree: null,
        subjectThreeSpeed: null,
        subjectThreeEvaluate: null,
        subjectFour: null,
        subjectFourSpeed: null,
        subjectFourEvaluate: null,
        subjectFive: null,
        subjectFiveSpeed: null,
        subjectFiveEvaluate: null,
        subjectSix: null,
        subjectSixSpeed: null,
        subjectSixEvaluate: null,
        subjectSeven: null,
        subjectSevenSpeed: null,
        subjectSevenEvaluate: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学员考试成绩管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAchievement(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学员考试成绩管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAchievement(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAchievement(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除学员考试成绩管理编号为"' + ids + '"的数据项？').then(function() {
        return delAchievement(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/achievement/export', {
        ...this.queryParams
      }, `achievement_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
